import multiprocessing

from baidubce.services.bos.bos_client import BosClient
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.bce_client_configuration import BceClientConfiguration

# 设置 BOS 相关信息
access_key_id = 'AK'
secret_access_key = 'SAK'
endpoint = 'http://su.bcebos.com'  # 根据你的地域选择相应的 endpoint
bucket_name = 'YOUR BucketName'
object_key = 'YOUR object_key'
# file_name = r"Z:\soft\geek.zip"
file_name = r"Z:\xxx.v151_20230426.tar.gz"


# 初始化 BOS 客户端
credentials = BceCredentials(access_key_id, secret_access_key)
config = BceClientConfiguration(credentials=credentials, endpoint=endpoint)
bos_client = BosClient(config)

# 封装分块上传
# 在Python SDK中，BOS为用户提供了put_super_obejct_from_file()接口，
# 它对分块上传涉及到的initiate_multipart_upload、upload_part_from_file、complete_multipart_upload三个方法进行封装，
# 用户只需调用该接口即可完成分块上传。
result = bos_client.put_super_obejct_from_file(bucket_name, object_key, file_name,
                                               chunk_size=5, thread_num=multiprocessing.cpu_count())
if result:
    print("Upload success!")
